<?php

/**
 * Class for viewing a jQuery object.
 * The input can be  a string such as 'document', or a CSS selector:
 * simple or nested, but not grouped.
 *
 * @author Ian Clarence ian.clarence@gmail.com
 */ 
class ViewJqueryObject {
    
    /**
     * A CSS selector as input.
     * 
     * @var ViewSelector
     */
    private $viewSelector;
    
    /**
     * A CSS nested selector as input.
     * 
     * @var ViewNestedSelector
     */
    private $viewNestedSelector;
    
    /**
     * A simple string as input, e.g. 'document'.
     * 
     * @var string
     */
    private $str;

    /**
     * The constructor.
     *
     * @param mixed $input
     */
    public function __construct($input) {
        if ($input instanceof ViewSelector) {
            $this->viewSelector = $input;
        }
        else if ($input instanceof ViewNestedSelector) {
            $this->viewNestedSelector = $input;
        }
        else if (is_string($input)) {
            $this->str = $input;
        }
    }
    
    /**
     * Viewing the object.
     * 
     * @return string
     */
    public function view() {
        if ($this->viewSelector) {
            return 'jQuery("' . $this->viewSelector->view() . '")';
        }
        if ($this->viewNestedSelector) {
            return 'jQuery("' . $this->viewNestedSelector->view() . '")';
        }
        if ($this->str) {
            return 'jQuery(' . $this->str . ')';
        }
    }
    
}